package com.lhb.SC.admin.feign.codec;

import feign.FeignException;
import feign.Response;
import feign.codec.DecodeException;
import feign.codec.Decoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.lang.reflect.Type;

@Slf4j
public class MonitorDecoder implements Decoder {

    private Decoder delegate;

    public MonitorDecoder(Decoder delegate) {
        log.info("MonitorDecoder.start.......................");
        log.info("MonitorDecoder.delegate={}", delegate);
        this.delegate = delegate;
    }

    @Override
    public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {
        try {
            Object result = delegate.decode(response, type);
            log.info(response.toString());
            return result;
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            throw e;
        } catch (FeignException e) {
            log.error(e.getMessage(), e);
            throw e;
        }
    }
}
